package core

import (
	"context"
	"golang.org/x/net/ipv4"
)

type Receiver interface {
	GetName() string
	StartReceiver() error
	StopReceiver()
}

type BaseReceiver struct {
	Ctx  context.Context
	Name string
	Task *TraceTask
	Stat *TraceStat

	Conn *ipv4.RawConn
}

func (r *BaseReceiver) GetName() string {
	return r.Name
}

func (r *BaseReceiver) StopReceiver() {
	if r == nil {
		return
	}

	if r.Conn != nil {
		r.Conn.Close()
	}
}

func AllocRxBuf(msgLen int) []byte {
	plen := msgLen + 80
	if plen < 1500 {
		plen = 1500
	}
	return make([]byte, plen)
}
